<?php
class YuyuecountAction extends CommonAction{
	public function data(){
		$method = $_POST;
		$methodget = $_GET;
		$uObj = new UserModel();
		$yObj = D('yuyue');
		switch($method['do']){
			case 'tongji':
				$d = getcity();
				$map['did'] = $d['did'];
				$userinfo = Session::get('userinfo');
				switch($userinfo['type_id']){
					case 1:
						$select = $uObj;
					break;
					case 2:
						$select = $uObj->where($map);
					break;
				}
				$tongji = $select->page(intval($methodget['page']),intval($methodget['limit']))->select();
				foreach($tongji as $v){
					$did[] = $v['id'];
				}
				$mapdid['uid'] = array('in',$did);
				$y = $yObj->where($mapdid)->field('max(date) as date,uid')->group('uid')->select();
				foreach($y as  $v){
					$y[$v['uid']] = $v['date'];
				}
				foreach($tongji as $k=>$v)
				{
					$tongji[$k]['date'] = toDate($y[$v['id']]);
				}
				$count = $select->count();
				echo json_encode(array('list'=>$tongji,'count'=>$count));
			break;
		}
	}
	public function search(){}
	public function index(){
		$this->display();
	}
}